package github._3y.algorithms;

import java.util.Arrays;

/**
 * @Author: DRevelation
 * @Date: 2021/1/20 19:53
 */
public class SelectSort {

    public static void main(String[] args) {
        int[] arr = new int[]{3, 1, 5, 2, 4};
        selectSort(arr);
        System.out.println("=======================");
        System.out.println("arr = " + Arrays.toString(arr));
    }

    private static void selectSort(int[] arr) {
        int pos;
        int temp;
        for (int i = 0; i < arr.length - 1; i++) {
            pos = 0;
            for (int j = 0; j < arr.length - i; j++) {
                if (arr[j] > arr[pos]) {
                    pos = j;
                }
            }
            temp = arr[pos];
            arr[pos] = arr[arr.length - 1 - i];
            arr[arr.length - 1 - i] = temp;
            System.out.println("arr = " + Arrays.toString(arr));
        }
    }

}
